<?php
class wideout_system{
	var $db_host = 'localhost';
	var $db_user = 'root';
	var $db_pass = '';
	var $db_name = 'wideout_system';

	function wideout_system(){
		$this->connection = @mysql_connect($this->db_host,$this->db_user,$this->db_pass);
		@mysql_select_db($this->db_name);
	}
	
	// BEGIN ADD FLAGS //
	
	public function addPermissions($name,$description){
		$query = "INSERT INTO permissions (permission,description,date_created) VALUES ('$name','$description',NOW())";
		$result = @mysql_query($query) or die(mysql_error());
		
		if($result){
			return true;
		}else{
			return false;
		}
	}
	
	public function addTimeShifts($name,$description){
		$query = "INSERT INTO time_shifts (time_shift,description, date_created) VALUES ('$name','$description',NOW())";
		$result = @mysql_query($query) or die(mysql_error());
		
		if($result){
			return true;
		}else{
			return false;
		}
	}
	
	public function addPositions($name,$description){
		$query = "INSERT INTO positions (position_name,description, date_created) VALUES ('$name','$description',NOW())";
		$result = @mysql_query($query) or die(mysql_error());
		
		if($result){
			return true;
		}else{
			return false;
		}
	}
	
	public function addEmployeeStatus($name,$description){
		$query = "INSERT INTO emp_status (status_name,description, date_created) VALUES ('$name','$description',NOW())";
		$result = @mysql_query($query) or die(mysql_error());
		
		if($result){
			return true;
		}else{
			return false;
		}
	}
	
	public function addDepartments($name,$description){
		$query = "INSERT INTO departments (department,description, date_created) VALUES ('$name','$description',NOW())";
		$result = @mysql_query($query) or die(mysql_error());
		
		if($result){
			return true;
		}else{
			return false;
		}
	}
	
	// END ADD FLAGS //
	
	
	// BEGIN CREATE USER //
	
	public function createUser($username, $password){
		$pass = md5($password);
		$query = "INSERT INTO wo_users (username,password,date_created) VALUES ('$username','$pass',NOW())";
		$result = @mysql_query($query) or die(mysql_error());
		
		if($result){
			return true;
		}else{
			return false;
		}
	}
	
	// END CREATE USER //
	
	public function createEmployee ($position, $user_id, $phones, $shift_id, $department_id, $firstname, $emails, $lastname, $birthdate, $sss, $tin, $philhealth, $acct_no, $emp_no, $emp_status){
		$query = "INSERT INTO wo_user_profile (position,user_id,firstname,lastname,birthdate,sss,tin,philhealth,acct_no,emp_no,emp_status,date_created) VALUES ($position,$user_id,'$firstname','$lastname','$birthdate','$sss','$tin','$philhealth','$acct_no','$emp_no',$emp_status,NOW())";
		$result = @mysql_query($query) or die(mysql_error());
		
		if($result){
			$query = "INSERT INTO wo_user_phones (user_id,phones,date_created) VALUES ($user_id, '$phones', NOW())";
			$result = @mysql_query($query) or die(mysql_error());
				if($result){
					$query = "INSERT INTO wo_user_emails (user_id,emails,date_created) VALUES ($user_id, '$emails', NOW())";
					$result = @mysql_query($query) or die(mysql_error());
					if($result){
						$query = "INSERT INTO wo_user_departments (user_id,department_id,date_created) VALUES ($user_id, $department_id, NOW())";
						$result = @mysql_query($query) or die(mysql_error());
						if($result){
							$query = "INSERT INTO wo_user_shifts (user_id,shift_id,date_created) VALUES ($user_id, $shift_id, NOW())";
							$result = @mysql_query($query) or die(mysql_error());
							if($result){
							return true;
							}
						}
					}
				}
	
		}else{
			return false;
		}
	}
}
?>